<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学员编号" prop="stuCode">
        <el-input
          v-model="queryParams.stuCode"
          placeholder="请输入学员编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学员姓名" prop="stuName">
        <el-input
          v-model="queryParams.stuName"
          placeholder="请输入学员姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别 0 男 1 女" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别 0 男 1 女" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="出生日期yyyy-MM-dd" prop="birthDay">
        <el-date-picker clearable size="small"
          v-model="queryParams.birthDay"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择出生日期yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="家长姓名" prop="stuParent">
        <el-input
          v-model="queryParams.stuParent"
          placeholder="请输入家长姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="首次签约时间 yyyy-MM-dd HH:mm:ss" prop="firstSignDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.firstSignDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择首次签约时间 yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="就读学校" prop="school">
        <el-input
          v-model="queryParams.school"
          placeholder="请输入就读学校"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前年级" prop="classLevel">
        <el-input
          v-model="queryParams.classLevel"
          placeholder="请输入当前年级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态  0 新建 1 购买订单 2 财务确认 -2 财务驳回 3 教管接收 4 分配学管" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态  0 新建 1 购买订单 2 财务确认 -2 财务驳回 3 教管接收 4 分配学管" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="归属咨询师" prop="tConsultId">
        <el-input
          v-model="queryParams.tConsultId"
          placeholder="请输入归属咨询师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归属学管" prop="tManageId">
        <el-input
          v-model="queryParams.tManageId"
          placeholder="请输入归属学管"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约课时" prop="signClasstimeNum">
        <el-input
          v-model="queryParams.signClasstimeNum"
          placeholder="请输入签约课时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="剩余课时" prop="surplusClasstimeNum">
        <el-input
          v-model="queryParams.surplusClasstimeNum"
          placeholder="请输入剩余课时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户总额" prop="totalMoney">
        <el-input
          v-model="queryParams.totalMoney"
          placeholder="请输入账户总额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户余额" prop="surplusMoney">
        <el-input
          v-model="queryParams.surplusMoney"
          placeholder="请输入账户余额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拓展字段1" prop="extand1">
        <el-input
          v-model="queryParams.extand1"
          placeholder="请输入拓展字段1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拓展字段2" prop="extand2">
        <el-input
          v-model="queryParams.extand2"
          placeholder="请输入拓展字段2"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拓展字段3" prop="extand3">
        <el-input
          v-model="queryParams.extand3"
          placeholder="请输入拓展字段3"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:student:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:student:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:student:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:student:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="拓展字段3" align="center" prop="id" />
      <el-table-column label="学员编号" align="center" prop="stuCode" />
      <el-table-column label="学员姓名" align="center" prop="stuName" />
      <el-table-column label="性别 0 男 1 女" align="center" prop="sex" />
      <el-table-column label="出生日期yyyy-MM-dd" align="center" prop="birthDay" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDay, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="家长姓名" align="center" prop="stuParent" />
      <el-table-column label="联系方式" align="center" prop="mobile" />
      <el-table-column label="首次签约时间 yyyy-MM-dd HH:mm:ss" align="center" prop="firstSignDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstSignDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="就读学校" align="center" prop="school" />
      <el-table-column label="当前年级" align="center" prop="classLevel" />
      <el-table-column label="状态  0 新建 1 购买订单 2 财务确认 -2 财务驳回 3 教管接收 4 分配学管" align="center" prop="status" />
      <el-table-column label="归属咨询师" align="center" prop="tConsultId" />
      <el-table-column label="归属学管" align="center" prop="tManageId" />
      <el-table-column label="签约课时" align="center" prop="signClasstimeNum" />
      <el-table-column label="剩余课时" align="center" prop="surplusClasstimeNum" />
      <el-table-column label="账户总额" align="center" prop="totalMoney" />
      <el-table-column label="账户余额" align="center" prop="surplusMoney" />
      <el-table-column label="拓展字段1" align="center" prop="extand1" />
      <el-table-column label="拓展字段2" align="center" prop="extand2" />
      <el-table-column label="拓展字段3" align="center" prop="extand3" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:student:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:student:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学员编号" prop="stuCode">
          <el-input v-model="form.stuCode" placeholder="请输入学员编号" />
        </el-form-item>
        <el-form-item label="学员姓名" prop="stuName">
          <el-input v-model="form.stuName" placeholder="请输入学员姓名" />
        </el-form-item>
        <el-form-item label="性别 0 男 1 女" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别 0 男 1 女">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期yyyy-MM-dd" prop="birthDay">
          <el-date-picker clearable size="small"
            v-model="form.birthDay"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生日期yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="家长姓名" prop="stuParent">
          <el-input v-model="form.stuParent" placeholder="请输入家长姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="首次签约时间 yyyy-MM-dd HH:mm:ss" prop="firstSignDate">
          <el-date-picker clearable size="small"
            v-model="form.firstSignDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择首次签约时间 yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="就读学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入就读学校" />
        </el-form-item>
        <el-form-item label="当前年级" prop="classLevel">
          <el-input v-model="form.classLevel" placeholder="请输入当前年级" />
        </el-form-item>
        <el-form-item label="状态  0 新建 1 购买订单 2 财务确认 -2 财务驳回 3 教管接收 4 分配学管">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="归属咨询师" prop="tConsultId">
          <el-input v-model="form.tConsultId" placeholder="请输入归属咨询师" />
        </el-form-item>
        <el-form-item label="归属学管" prop="tManageId">
          <el-input v-model="form.tManageId" placeholder="请输入归属学管" />
        </el-form-item>
        <el-form-item label="签约课时" prop="signClasstimeNum">
          <el-input v-model="form.signClasstimeNum" placeholder="请输入签约课时" />
        </el-form-item>
        <el-form-item label="剩余课时" prop="surplusClasstimeNum">
          <el-input v-model="form.surplusClasstimeNum" placeholder="请输入剩余课时" />
        </el-form-item>
        <el-form-item label="账户总额" prop="totalMoney">
          <el-input v-model="form.totalMoney" placeholder="请输入账户总额" />
        </el-form-item>
        <el-form-item label="账户余额" prop="surplusMoney">
          <el-input v-model="form.surplusMoney" placeholder="请输入账户余额" />
        </el-form-item>
        <el-form-item label="拓展字段1" prop="extand1">
          <el-input v-model="form.extand1" placeholder="请输入拓展字段1" />
        </el-form-item>
        <el-form-item label="拓展字段2" prop="extand2">
          <el-input v-model="form.extand2" placeholder="请输入拓展字段2" />
        </el-form-item>
        <el-form-item label="拓展字段3" prop="extand3">
          <el-input v-model="form.extand3" placeholder="请输入拓展字段3" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStudent, getStudent, delStudent, addStudent, updateStudent } from "@/api/biness/student";

export default {
  name: "Student",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuCode: null,
        stuName: null,
        sex: null,
        birthDay: null,
        stuParent: null,
        mobile: null,
        firstSignDate: null,
        school: null,
        classLevel: null,
        status: null,
        tConsultId: null,
        tManageId: null,
        signClasstimeNum: null,
        surplusClasstimeNum: null,
        totalMoney: null,
        surplusMoney: null,
        extand1: null,
        extand2: null,
        extand3: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuCode: null,
        stuName: null,
        sex: null,
        birthDay: null,
        stuParent: null,
        mobile: null,
        firstSignDate: null,
        school: null,
        classLevel: null,
        status: 0,
        tConsultId: null,
        tManageId: null,
        signClasstimeNum: null,
        surplusClasstimeNum: null,
        totalMoney: null,
        surplusMoney: null,
        extand1: null,
        extand2: null,
        extand3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStudent(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delStudent(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/student/export', {
        ...this.queryParams
      }, `system_student.xlsx`)
    }
  }
};
</script>
